<?php

function list_kelompok_pengantian(){

//PASANG JAVASCRIPT
my_set_code_js('

function confirmDelete(id){
	var t = confirm(\'Yakin akan menghapus data ?\');
	if(t){
		location.href=\'index.php?com=kelompok_pengantian&task=delete&id=\'+id;
	}
	return false;
}

');
	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'Nama Biaya Kesehatan'=>array('style'=>'border-bottom:2px solid;width:30%'),    
		'PKB'=>array('style'=>'border-bottom:2px solid;width:25%'),    
		'tentang'=>array('style'=>'border-bottom:2px solid;width:30%'),    
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);

	$query = "SELECT * FROM pengantian_kelompok  ORDER BY pengantian_kelompok_id ASC";
	$result = my_query($query);
	$i = 0;
	$row=array();
	while($ey = my_fetch_array($result)){
		$i++;
		$editproperty = array(
						'href'=>'index.php?com=kelompok_pengantian&task=editkelompok_pengantian&id='.$ey['pengantian_kelompok_id'],
						'rel'=>'facebox',
						'title'=>'Edit'
				);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );

		$deleteproperty = array(
						'href'=>'javascript:; ',
						'onclick'=>'javascript:confirmDelete('.$ey['pengantian_kelompok_id'].');',
						'title'=>'Delete'
				);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		 
		$row[] = array(
			'#'=>position_text_align ($i, 'center'),  
			'm'=>  $ey['label']  ,    
			'pkb'=>  $ey['pkb']  ,    
			'tentang'=>  $ey['tentang']  ,    
			'operasi'=> position_text_align(  $edit_button.' '.$delete_button , 'right'),  
		);
		 
	}
	
	$datas = table_rows($row);  
	$menuontop = array(  
		'Tambah data'=>array('onclick'=>'javascript:jQuery.facebox({ ajax: \'index.php?com=kelompok_pengantian&task=editkelompok_pengantian&id=0\' })'),
		//'Export to excel'=>array('onclick'=>'javascript:location.href=\'index.php?com=csv&task=excel_daftar_karyawan\''),
		'Cetak' => array('onclick'=>'javascript:window.open(\'index.php?com=report&task=all_kelompok_pengantian\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');')
	); 
	$printmenu = additional_menu_on_list( $menuontop ,'');
	return  table_builder($header , $datas ,  3 , false );
}

function form_kelompok_pengantian_validate($id){
	$errsubmit = false;
	$err = array();
	 
	$code =  trim($_POST["label"]); 
	if( $code == ''){
		$errsubmit = true;
		$err[] ="Nama kelompok belum diisi";
	}
	
	$query="SELECT pengantian_kelompok_id FROM pengantian_kelompok 
		WHERE label='".$code.
		"' AND pengantian_kelompok_id<>".$id; 
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Nama kelompok sudah digunakan";
	}
	
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}

function form_kelompok_pengantian_submit($id){
	$datas = array( 
		'label'=>my_type_data_str( $_POST['label'] ),  
		'pkb'=>my_type_data_str( $_POST['pkb'] ),  
		'tentang'=>my_type_data_str( $_POST['tentang'] ),  
	);
	if($id > 0){
		return my_update_record('pengantian_kelompok' ,'pengantian_kelompok_id' , $id , $datas);
	}
	
	return my_insert_record('pengantian_kelompok' , $datas);
}

function form_kelompok_pengantian_create($id = 0){
	$view = form_header( "pengantian_kelompok" , "kelompok_pengantian"  );
 	$fields = my_get_data_by_id('pengantian_kelompok','pengantian_kelompok_id',$id);
	 
	$temp = array(
				'name'=>'label',
				'value'=>( isset($_POST['label']) ? $_POST['label'] : $fields['label'] ),
				'id'=>'label',
				'type'=>'label',
				'size'=>'45'
			);
	$form_temp = form_dynamic($temp);	
	$view .= form_field_display( $form_temp  , "Nama kelompok"  );   

	$temp = array(
				'name'=>'pkb',
				'value'=>( isset($_POST['pkb']) ? $_POST['pkb'] : $fields['pkb'] ),
				'id'=>'pkb',
				'type'=>'label',
				'size'=>'45'
			);
	$form_temp = form_dynamic($temp);	
	$view .= form_field_display( $form_temp  , "PKB"  );   

	$temp = array(
				'name'=>'tentang',
				'value'=>( isset($_POST['tentang']) ? $_POST['tentang'] : $fields['tentang'] ),
				'id'=>'tentang',
				'type'=>'label',
				'size'=>'45'
			);
	$form_temp = form_dynamic($temp);	
	$view .= form_field_display( $form_temp  , "tentang"  );   
	
		$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
} 

function remove_kelompok_pengantian($id){
	$query= "DELETE FROM pengantian_kelompok WHERE pengantian_kelompok_id = {$id}";
	return my_query($query);
} 
 